<extend name="common:commonTemplate"/>
<block name="main_content">
    <style>
        .container-fluid input {width: 50%;}
        .filter_select {
        		background-color:#efefef;
			    border: 1px solid #cdcdcd;
			    font-size: 12px;
			    height: 25px;
			    margin-top: 6px;
			    vertical-align: middle;
			    width: 100px;
		}
		.filter_select::-ms-expand { display: none; }
    </style>
    <div id="content">
        <div id="content-header">
            <div id="breadcrumb">
                <a class="tip-bottom" href="index.html" data-original-title="Go to Home">
                	<i class="icon-home"></i>首页
                 </a> 
                 <a href="#">会议管理</a>
                 <a href="/meeting/meetingList">会议查询</a>
                 <a class="current" href="#">
           	    	<if condition="$operation == 'EDIT'">会议编辑<else />会议新增</if>
                 </a>
            </div>
        </div>
        <div class="container-fluid">
        	<!-- 会议信息层 -->
            <div class="row-fluid">
                <div class="span12">
                    <div class="widget-box">
                        <div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
                            <h5>会议信息</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <form novalidate="novalidate" id="basic_validate"
                                  name="basic_validate" action="#" method="post"
                                  class="form-horizontal">
                                <div class="control-group">
                                    <label class="control-label">会议主题<span class="required-tips">*</span></label>
                                    <div class="controls">
                                    	<input type="hidden" id="meeting_id" name="meeting_id" value="{$mtg.meeting_id}">
                                        <input type="text" id="meeting_name" name="meeting_name" value="{$mtg.meeting_name}"/>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">开始时间<span class="required-tips">*</span></label>
                                    <div class="controls">
                                    	<input id="start_time" name="start_time" value="{$mtg.start_time}" class="date_controller" onclick="laydate({elem: '#start_time', istime: true, format: 'YYYY-MM-DD hh:mm:ss', choose:MeetingPage.changeStartTime})" >
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">结束时间<span class="required-tips">*</span></label>
                                    <div class="controls">
                                        <input id="end_time" name="end_time" value="{$mtg.end_time}" class="date_controller" onclick="laydate({elem: '#end_time', istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
                                    </div>
                                </div>
                                
                                <div class="control-group">
                                    <label class="control-label">签到范围(开始前)<span class="required-tips">*</span></label>
                                    <div class="controls">
                                        <input id="sign_in_from" name="sign_in_from" value="{$mtg.sign_in_from}" class="date_controller" onclick="laydate({elem: '#sign_in_from', istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
                                    </div>
                                </div>
                                
                                <div class="control-group">
                                    <label class="control-label">签到范围(开始后)<span class="required-tips">*</span></label>
                                    <div class="controls">
                                        <input id="sign_in_to" name="sign_in_to" value="{$mtg.sign_in_to}" class="date_controller" onclick="laydate({elem: '#sign_in_to', istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
                                    </div>
                                </div>
                                
                                <div class="control-group">
                                    <label class="control-label">备注</label>
                                    <div class="controls">
                                        <textarea rows="3" cols="4" id="remark" name="remark"   style="width: 50%;">{$mtg.remark}</textarea>
                                    </div>
                                </div>
                                
                                <div class="control-group">
                                    <if condition="$operation == 'EDIT'">
                                    	<a id="btn_submit_meeting" class="btn btn-success">更新会议</a>
                                    	<a id="btn_report" class="btn btn-success" href="/meeting/meetingRecordExcel?meeting_id={$mtg.meeting_id}" target="_blank">明细导出</a>
                                    <else />
                                    	<a id="btn_submit_meeting" class="btn btn-success">新增会议</a>
                                    </if>
                                    <a id="btn_add_member" style="background:red" class="btn btn-success" href="#" >
		                            	获取可参加员工
		                            </a>
                                    <a id="btn_qr_code" style="background:red" class="btn btn-success" href="#" >二维码生成</a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
       	<div class="container-fluid">
            <!-- 参加人明细层 -->
            <div class="row-fluid">
                <div class="span12">
                    <div class="widget-box">
                        <div class="widget-title"><span class="icon"> <i class="icon-th"></i> </span>
                            <h5>参加人信息</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <table id="search_result" page_index="1" class="table table-bordered table-striped">
                                <thead>
	                                <tr>
	                                    <th style="vertical-align: middle;">员工编码</th>
	                                    <th style="vertical-align: middle;">姓名</th>
	                                    <th>签到状态
			                                    <select id="sign_in_filter" name="sign_in_filter" class="filter_select" onchange="MeetingPage.doFilter()">
					                            	<option value="" selected="selected">全部</option>
					                            </select>
	                                    </th>
	                                    <th style="vertical-align: middle;">签到时间</th>
	                                    <th>签退状态
	               	                            <select id="sign_off_filter" name="sign_off_filter" class="filter_select"  onchange="MeetingPage.doFilter()">
					                            	<option value="" selected="selected">全部</option>
					                            </select>
                                    	</th>
	                                    <th style="vertical-align: middle;">签退时间</th>
	                                    <th style="vertical-align: middle;">来源</th>
	                                    <th style="vertical-align: middle;">创建人</th>
	                                    <th style="vertical-align: middle;">创建时间</th>
	                                </tr>
                                </thead>
                                <tbody></tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
          </div>
          <div class="container-fluid">
            <!-- 添加层 -->
            <div class="row-fluid">
                <div class="span12">
                    <div class="widget-box">
                        <div class="widget-title"><span class="icon"> <i class="icon-th"></i> </span>
                            <h5>本次添加的员工</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <table id="tmp_result" page_index="1" class="table table-bordered table-striped">
                                <thead>
	                                <tr>
	                                    <th>员工编码</th>
	                                    <th>姓名</th>
	                                    <th width="100px">操作</th>
	                                </tr>
                                </thead>
                                <tbody></tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</block>
<block name="js_content">
    <script src="/Public/js/ajaxService.js?v=12" type="text/javascript"></script>
    <script src="/Public/js/common.js?v=16" type="text/javascript"></script>
    <script src="/Public/js/laydate/laydate.js" type="text/javascript"></script> 
    <script src="/Public/assets/js/layer/layer.js" type="text/javascript"></script>
    <script>
        $(function(){
            MeetingPage = {
                'Init': function () {
                	MeetingPage.tmp_member = new Array();
                	//给予新增/更新会议按钮绑定事件
                    $('#btn_submit_meeting').bind('click', function () {
                    	var param = {};
                    	param.meeting_name = $('#meeting_name').val();
                    	param.start_time = $('#start_time').val();
                    	param.end_time = $('#end_time').val();
                    	param.remark = $('#remark').val();
                    	param.sign_in_from = $('#sign_in_from').val();
                    	param.sign_in_to = $('#sign_in_to').val();
                    	param.meeting_id = "{$mtg.meeting_id}";
                    	param.member_count = "{$mtg.member_count}";
                    	param.members = MeetingPage.tmp_member;
                    	$.ajax({
                            type: 'post',
                            url: '/AjaxService/center/meeting/saveorupdate',
                            data: param,
                            dataType: 'json',
                            success: function (data) {
                                if (data.IsSuccess == 0) {
                                	layer.msg(data.ErrorMsg, {icon: 5});
                                    return;
                                } else {
                                	layer.msg('操作成功', {icon: 0});
                                }
                            },
                            error: function (e, err_name, err_text) {
                            	layer.msg(err_text, {icon: 5});
                            }
                        });
                    });
                	//签到签退筛选赋值
               		$.each(MeetingPage.sign_in_options, function(code, display){
               			$("#sign_in_filter").append("<option value='"+code+"'>"+display+"</option>");
              		});
                    $.each(MeetingPage.sign_off_options, function(code, display){
               			$("#sign_off_filter").append("<option value='"+code+"'>"+display+"</option>");
              		});
                    //拉取成员赋值
                   	$('#btn_add_member').bind('click', function () {
                   		MeetingPage.getTagMember("{$mtg.meeting_id}");
                    });
                    //二维码生成
                   	$('#btn_qr_code').bind('click', function () {
                   		MeetingPage.showQrCode($('#start_time').val());
                    });
                    
                },
                'LoadMember': function(page_index){
                	//会议CODE为空时 初始化不查询联系人 构造空的查询结果页面
                	if(CommonPage.convertNull("{$mtg.meeting_id}") == ''){
                		 MeetingPage.fillMemberTable([],'','');
                	}else{
                		var param = {};
                    	param.meeting_id = "{$mtg.meeting_id}";
	                    $.ajax({
	                        type: 'post',
	                        url: '/AjaxService/center/meeting/querymembersbymeetingid',
	                        data: param,
	                        dataType: 'json',
	                        async: true,
	                        success: function (data) {
	                        	MeetingPage.memberData = data.Result;
	                            MeetingPage.fillMemberTable(data.Result,'','');
	                        },
	                        error: function (e, err_name, err_text) {
	                        	layer.msg(err_text, {icon: 5});
	                        }
	                    });
                	}
                },
                'fillMemberTable': function(lst_member,sign_in_code,sign_off_code){
                	var html = '';
                    if (lst_member.length == 0) {
                        $('#search_result tbody').html('');
                        html = "<tr ><td colspan='16' style='text-align:center'>暂无数据!</td></tr>";
                    }else{
                        for (var index in lst_member) {
                            var member_en = lst_member[index];
                            //只有sign_in_code/sign_off_code没有选择或者数据与选择的sign_in_code/sign_off_code匹配的情况下才会输出
                            if((sign_in_code == '' || sign_in_code == member_en.sign_in_sts ) && 
                            		(sign_off_code == '' || sign_off_code == member_en.sign_off_sts)){
	                            html += "<tr>";
	                            html += "<td>" + CommonPage.convertNull(member_en.employee_code) + "</td>";
	                            html += "<td>" + CommonPage.convertNull(member_en.employee_name) + "</td>"
	                            html += "<td "+ MeetingPage.signInStyle(member_en.sign_in_sts) +" >" + MeetingPage.ConvertOptions('sign_in_options',member_en.sign_in_sts) + "</td>"
	                            html += "<td>" + CommonPage.convertNull(member_en.sign_in_time) + "</td>"
	                            html += "<td>" + MeetingPage.ConvertOptions('sign_off_options',member_en.sign_off_sts) + "</td>"
	                            html += "<td>" + CommonPage.convertNull(member_en.sign_off_time) + "</td>"
	                            html += "<td>" + MeetingPage.ConvertOptions('from_type_options',member_en.from_type) + "</td>"
	                            html += "<td>" + CommonPage.convertNull(member_en.create_user) + "</td>";
	                            html += "<td>" + CommonPage.convertNull(member_en.create_date) + "</td>";
	                            /* html += "<td>" + "<a style='color:blue;' href='/customer/editCustomerPage?cust_id=" + member_en.id + "'>查看详情</a></td>" */
	                            html += "</tr>";
                            }
                        }
                    }
                    $('#search_result tbody').html('');
                    $('#search_result tbody').append(html);
                },
                'addTmpTag': function(tmp_member){
	               	if (tmp_member.length == 0) {
	               		return;
	               	}
	               	MeetingPage.tmp_member = tmp_member;
                	var html = '';
                    for (var index in tmp_member) {
                         var member_en = tmp_member[index];
                         html += "<tr id='tmp_lst'>";
                         html += "<td>" + CommonPage.convertNull(member_en.user_id) + "</td>";
                         html += "<td>" + CommonPage.convertNull(member_en.name) + "</td>"
                         html += "<td style='text-align: center;'>" + "<a style='color:blue;' user_id="+member_en.user_id+" user_name="+member_en.name+" href='#' onclick='MeetingPage.removeTmp(this)'>删除</a></td>" 
                         html += "</tr>";
                    }
                    $('#tmp_result tbody').html('');
                    $('#tmp_result tbody').append(html);
                },
                'removeTmp': function(obj){
                	var tmp = {user_id:$(obj).attr('user_id'),name:$(obj).attr('user_name')}
                	MeetingPage.tmp_member.splice($.inArray(tmp,MeetingPage.tmp_member),1);
	               	$(obj).parent().parent().remove();
	               	if($('#tmp_lst').children().size() == 0){
	               		$('#search_result tbody').html('');
                        html = "<tr ><td colspan='16' style='text-align:center'>暂无数据!</td></tr>";
	               	}
                },
                'getTagMember' : function(id){ //获取微信标签内用户
                    layer.open({
                        type: 2,
                        title: '参加人员',
                        fix: true,
                        shadeClose: true,
                        maxmin: true,
                        area: ['500px', '500px'],
                        content: '/meeting/getTagMember?meeting_id='+id,
                        end: function () {
                            layer.tips('完成选择', '#photosDemo', {tips: 1})
                        }
                    });
                },
                'showQrCode' : function(start_time){
                	if(start_time == null || start_time == ''){
                		layer.msg('无效会议开始时间,无法生成二维码', {icon: 5});
                	}else{
	                    layer.open({
	                        type: 2,
	                        title: start_time + '-会议二维码',
	                        fix: true,
	                        shadeClose: true,
	                        maxmin: false,
	                        area: ['380px', '410px'],
	                        content: '/meeting/meetingQrCode?start_time='+start_time
	                    });
                	}
                },
                "doFilter" : function(){
                    MeetingPage.fillMemberTable(MeetingPage.memberData,$('#sign_in_filter').val(),$('#sign_off_filter').val());
                },
        		'ConvertOptions': function(type,obj){
        			var display = '【转换失败:'+obj+'】';
        			$.each(MeetingPage[type], function(key, value){
        			  if(key == obj){
        				  display = value;
        				  return false;
        			  }
        			});
        			return display;
        		},
        		'signInStyle': function(obj){
   			  		var style = ''
       			  	switch(obj){
	        		  case 'NONE': //缺席或者未签到
	        			 style = 'style="color: #CD5C5C;"';
	    				 break;
	    			  case 'NORMAL': //签到
	    				 style = 'style="color: #32CD32;"';
	    				 break;
	    			  case 'LATE': //迟到
	    				 style = 'style="color: #FFD700;"';
	    				 break;
	    			  default:
   			  		}
       				return style;
        		},
        		'changeStartTime': function(start_date){
        			if(end_time.value == ''){
        				end_time.min = start_date;
            			end_time.value = start_date;
        			}else{
        				var s_date = new Date(start_date);
            			var e_date = new Date(end_time.value);
            			if(s_date.getTime() > e_date.getTime()){
            				end_time.min = start_date;
                			end_time.value = start_date;
            			}
        			}
        			sign_in_from.min = start_date;
        			sign_in_from.value = start_date;
        			sign_in_to.min = start_date;
        			sign_in_to.value = start_date;
        		}
            };
            $(document).ready(function () {
            	MeetingPage.sign_in_options = eval({$sign_in_options});
            	MeetingPage.sign_off_options = eval({$sign_off_options});
            	MeetingPage.from_type_options = eval({$from_type_options});
                MeetingPage.Init();
                MeetingPage.LoadMember(1);
            });
        });
    </script>
</block>